home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / mod2tutr.zip / CHAP09.TXT < prev    next >
Text File  |  1989-01-18  |  6KB  |  175 lines

  1.  
  2.                                                      Chapter 9
  3.  
  4.                                               EXAMPLE PROGRAMS
  5.  
  6.  
  7.  
  8. WHY THIS CHAPTER?
  9. ______________________________________________________________
  10.  
  11. The programs included in this chapter are intended to be
  12. illustrations to you in how to write a complete program.  The
  13. programs are meant to be useful to you either as an example
  14. of how to do some operation or as utility programs for your
  15. own personal use.
  16.  
  17.  
  18. TIMEDATE - Get Time and Date
  19. ______________________________________________________________
  20.  
  21. This program calls one of the DOS             ================
  22. functions to get the current time and           TIMEDATE.MOD
  23. date.  The various components of the time     ================
  24. and date are input as variables and can be
  25. printed or displayed in any format you desire.  Your
  26. particular compiler may use a different format because there
  27. is no standard in Modula-2.  This is one of those areas that
  28. will probably deviate from compiler to compiler.  If you study
  29. your documentation that came with your compiler, you will find
  30. many other calls of this type described.  This program is
  31. meant to be an illustration of how to use this particular
  32. call.  Note that this program is especially written to use the
  33. MS-DOS calls available on an IBM-PC microcomputer and will
  34. probably have no resemblance to the calls on some other
  35. system.
  36.  
  37.  
  38. AREAS - Calculate Areas
  39. ______________________________________________________________
  40.  
  41. This program is presented as an                ===============
  42. illustration of how to build up a larger          AREAS.MOD
  43. program than any we have examined up to        ===============
  44. this point.  Notice that the main program
  45. is simply one CASE statement that calls all of the other
  46. procedures.  It would be very simple to include the code from
  47. each procedure right in the CASE statement and have no
  48. procedure calls, but it would make the program a little more
  49. difficult to understand.  The way this example is formatted,
  50. the code is very easy to understand.  After you understand the
  51. main program, it is a simple matter to visit each procedure
  52. to see exactly what they do.
  53.  
  54. Observe carefully how the menu works in this program.  It
  55. reads one keystroke and responds immediately making it a very
  56. simple program to use.
  57.  
  58.                                                            9-1
  59.  
  60.                                   Chapter 9 - Example Programs
  61.  
  62. PC - Printer Control
  63. ______________________________________________________________
  64.  
  65. This is a very useful program that you can    ================
  66. use to control your printer.  It is                PC.MOD
  67. specifically set up for an Epson RX-80,       ================
  68. but you can modify the control characters
  69. to set up your printer to whatever mode you desire.  To use
  70. it, you call the program by typing its name on the DOS command
  71. line, and supply a single letter according to the displayed
  72. menu.  The program will send the requested control sequences
  73. to the printer to select the enhanced, compressed, or whatever
  74. mode you desire.  If your printer is located physically remote
  75. from you, you can use this program to send a formfeed to the
  76. printer by selecting the F option.  If you have some longer
  77. control sequences to send, you may want to store the values
  78. in a string and use a loop to output the data until you come
  79. to an 0C character.
  80.  
  81.  
  82.  
  83. LIST - List Program File
  84. ______________________________________________________________
  85.  
  86. If you ran the batch file named LISTALL as    ================
  87. suggested at the beginning of this                LIST.MOD
  88. tutorial to print out all of the source       ================
  89. files, you have already used a program
  90. similar to this one.  This program will list any ASCII file,
  91. adding line numbers, page numbers, and the date and time, on
  92. the printer.  It is specifically designed to be a program
  93. listing utility.  The operation is very simple, and you should
  94. have no trouble in understanding this program or what it does.
  95.  
  96. Feel free to modify this program for your own personal use.
  97.  
  98. The LIST.EXE file on the distribution disk is not a result of
  99. compiling this source file but was written and compiled in
  100. TURBO Pascal.  This was done in order to alleviate the
  101. possibility of any legal problem, because Borland
  102. International does not require a distribution fee or a run-
  103. time license for compiled programs.  The Modula-2 program is
  104. nearly identical to the distributed executable program, and
  105. allows you to modify the source code to meet your own personal
  106. needs.
  107.  
  108. Additional programs will be given at the end of Part III for
  109. your information.  You will no doubt find additional example
  110. programs in various books and periodicals and it would be to
  111. your advantage to spend some time studying them as
  112. illustrations of both good and bad practices.
  113.  
  114.  
  115.  
  116.                                                            9-2
  117.  
  118.                                   Chapter 9 - Example Programs
  119.  
  120. PROGRAMMING EXERCISE
  121. ______________________________________________________________
  122.  
  123. 1.   Study the source code for LIST.EXE for a period of time,
  124.      then compile it with your compiler.  You may need a few
  125.      modifications to get it to compile properly because all
  126.      Modula-2 compilers are not identical.  After successfully
  127.      compiling and executing this program, put it aside.
  128.      Starting with a blank sheet of paper, write and debug
  129.      your own version of a program lister.  This is a fairly
  130.      major programming assignment, but if you get stuck, you
  131.      have the existing program to help you over the rough
  132.      spots.  If you complete this assignment, you will have
  133.      gained a good bit of experience in writing Modula-2, and
  134.      you will have your own customized program lister that you
  135.      thoroughly understand.
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.                                                            9-3
  174.  
  175.